package yxy.cherry.game.base.message;

import com.google.protobuf.MessageLite;

import yxy.cherry.game.base.message.annotation.MessageSource;

public class MessageEmitterHandler implements IMessageEmitter {
	static private MessageEmitterHandler instance;

	public static MessageEmitterHandler getInstance() {
		if (instance == null) {
			instance = new MessageEmitterHandler();
		}
		return instance;
	}

	private MessageEmitterHandler() {
	}

	private IMessageEmitter emitter;

	public void initMessageEmitter(IMessageEmitter emitter) {
		this.emitter = emitter;
	}

	public IMessageEmitter getMessageEmitter() {
		return emitter;
	}

	@Override
	public boolean send(int uid, MessageLite message) {
		try {
			return emitter.send(uid, message);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean send(String pcode, MessageLite message) {
		try {
			return emitter.send(pcode, message);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean send(MessageSource source, MessageLite message) {
		try {
			return emitter.send(source, message);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean control(String tag, long source, long destination, int proto, MessageLite message) {
		try {
			return emitter.control(tag, source, destination, proto, message);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
